import { User } from 'my-web-core/auth';
import React from 'react';
import { Route } from 'react-router-dom';

import { getGuardedElement } from '@/shared/components/RouterHelper';

const rootPath: string = '/users';
const listPath: string = 'list';
const detailPath: string = 'detail';

const UserList = React.lazy(() => import('@/features/users/components/UserList'));
const UserDetail = React.lazy(() => import('@/features/users/components/UserDetail'));

function getUserRoute(currentUser: User | null) {
  return (
    <Route path={rootPath}>
      <Route
        path={listPath}
        element={getGuardedElement(`${rootPath}/${listPath}`, <UserList />, currentUser)}
      />
      <Route
        path={`${detailPath}/:id`}
        element={getGuardedElement(`${rootPath}/${detailPath}`, <UserDetail />, currentUser)}
      />
    </Route>
  );
}

export default getUserRoute;
